function JumpSlashDamageEnum takes nothing returns nothing
	local unit target = GetEnumUnit()
	//--
	if IsUnitEnemy(target , udg_TempPlayer) and IsUnitInRangeLoc(target , udg_TempLocation , udg_TempRadius) and not IsUnitType(target , UNIT_TYPE_STRUCTURE) and GetUnitState(target , UNIT_STATE_LIFE) > 0.0 then
		set udg_TempHitCount = udg_TempHitCount + 1
		call UnitDamageTarget(udg_TempDamager , target , udg_TempDamage , true , false , ATTACK_TYPE_NORMAL, DAMAGE_TYPE_COLD , WEAPON_TYPE_METAL_MEDIUM_BASH)
	endif
	//--
	set target = null
endfunction

function JumpSlashDamage takes unit jumper returns nothing
	local integer abilityLevel = GetUnitAbilityLevel(jumper , 'A020')
	local item weapon = GetWeaponOfType(jumper , StringHash("TWO_HANDED"))
	local real weaponDamage = LoadReal(udg_ItemDataHashTable , GetHandleId(weapon) , StringHash("WEAPON_DAMAGE"))
	local real weaponRangeBonus = LoadReal(udg_ItemDataHashTable , GetHandleId(weapon) , StringHash("RANGE_BONUS"))
	local real mastery = LoadReal(udg_UnitDataHashTable , GetHandleId(jumper) , StringHash("JUMP_SLASH_MASTERY"))
	//--
	set udg_TempDamager = jumper
	set udg_TempPlayer = GetOwningPlayer(jumper)
	set udg_TempDamage = 50.0 + weaponDamage * mastery * 0.2
	set udg_TempRadius = 100.0 + I2R(abilityLevel - 1) * 50 + weaponRangeBonus
	set udg_TempHitCount = 0
	set udg_TempLocation = GetUnitLoc(jumper)
	call For(GetUnitsInRangeOfLocMatching(udg_TempRadius + 70.0 , udg_TempLocation , null) , function JumpSlashDamageEnum)
	call RemoveLocation(udg_TempLocation)
	call UnitUsedAbilityWithDelta(jumper , 'A020' , 0.5 + I2R(udg_TempHitCount) * 0.3)
	//--
	set weapon = null
endfunction

function JumpSlashRoutine takes nothing returns nothing
	local timer jumpTimer = GetExpiredTimer()
	local integer jumpTimerId = GetHandleId(jumpTimer)
	local unit jumper = LoadUnitHandle(udg_HT , jumpTimerId , StringHash("CASTER"))
	local real jumperX = GetUnitX(jumper)
	local real jumperY = GetUnitY(jumper) 
	local real dx = LoadReal(udg_HT , jumpTimerId , StringHash("DX"))
	local real dy = LoadReal(udg_HT , jumpTimerId , StringHash("DY"))
	local real timeNow = LoadReal(udg_HT , jumpTimerId , StringHash("TIME_NOW"))
	local real timeMax = LoadReal(udg_HT , jumpTimerId , StringHash("TIME_MAX"))
	local real maxFlyHeight = LoadReal(udg_HT , jumpTimerId , StringHash("MAX_FLT_HEIGHT"))
	//--
	if timeNow < timeMax then
		set timeNow = timeNow + 0.01
		call SaveReal(udg_HT , jumpTimerId , StringHash("TIME_NOW") , timeNow)
		call SetUnitX(jumper , jumperX + dx)
		call SetUnitY(jumper , jumperY + dy)
		call SetUnitFlyHeight(jumper , -(4.0 * maxFlyHeight / (timeMax * timeMax)) * timeNow * timeNow + (4.0 * maxFlyHeight / timeMax) * timeNow , 0.0)
		if timeNow == 0.3 then
			call SetUnitTimeScale(jumper , 0.1)
		elseif timeNow == 0.5 then
			call SetUnitTimeScale(jumper , 1.5)
		endif
	else
		call PauseTimer(jumpTimer)
		call FlushChildHashtable(udg_HT , jumpTimerId)
		call DestroyTimer(jumpTimer)
		
		call JumpSlashDamage(jumper)
			
		call PauseUnit(jumper , false)
		call SetUnitTimeScale(jumper , 1.0)
		call SetUnitPathing(jumper , true)
		
		call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Human\\Thunderclap\\ThunderClapCaster.mdl" , GetUnitX(jumper) , GetUnitY(jumper)))
	endif
	//--
	set jumpTimer = null
	set jumper = null
endfunction

function JumpSlashAction takes nothing returns nothing
	local unit jumper = GetTriggerUnit()
	local location jumperLocation = GetUnitLoc(jumper)
	local real jumperX = GetLocationX(jumperLocation)
	local real jumperY = GetLocationY(jumperLocation)
	local location spellTargetLocation = GetSpellTargetLoc()
	local real angle = AngleBetweenPoints(jumperLocation , spellTargetLocation)
	local real distance = DistanceBetweenPoints(jumperLocation , spellTargetLocation)
	local real timeInterval = 0.01
	local real flyTime = 0.7
	local real maxFlyHeight = 500.0
	local real xySpeed = distance / flyTime
	local real delta = xySpeed * timeInterval
	local real dx = Cos(angle * bj_DEGTORAD) * delta
	local real dy = Sin(angle * bj_DEGTORAD) * delta
	local timer jumpTimer = CreateTimer()
	local integer jumpTimerId = GetHandleId(jumpTimer)
	//--
	call UnitAddAbility(jumper , 'Arav')
	call UnitRemoveAbility(jumper , 'Arav')
	call SetUnitFlyHeight(jumper , 0.0 , 0.0)
	call PauseUnit(jumper , true)
	call SetUnitTimeScale(jumper , 0.5)
	call SetUnitPathing(jumper , false)
	call SetUnitAnimationByIndex(jumper , 33)
	call SaveUnitHandle(udg_HT , jumpTimerId , StringHash("CASTER") , jumper)
	call SaveReal(udg_HT , jumpTimerId , StringHash("DX") , dx)
	call SaveReal(udg_HT , jumpTimerId , StringHash("DY") , dy)
	call SaveReal(udg_HT , jumpTimerId , StringHash("TIME_NOW") , 0.0)
	call SaveReal(udg_HT , jumpTimerId , StringHash("TIME_MAX") , flyTime)
	call SaveReal(udg_HT , jumpTimerId , StringHash("MAX_FLT_HEIGHT") , maxFlyHeight)
	call TimerStart(jumpTimer , timeInterval , true , function JumpSlashRoutine)
	call RemoveLocation(jumperLocation)
	call RemoveLocation(spellTargetLocation)
	//--
	set jumper = null
	set jumperLocation = null
	set spellTargetLocation = null
	set jumpTimer = null	
endfunction

function JumpSlashTry takes nothing returns nothing
	if GetSpellAbilityId() == 'A020' then
		call JumpSlashAction()
	endif
endfunction

function InitTrig_JumpSlash takes nothing returns nothing
	local hashtable masteryTable = InitHashtable()
	local integer abilityId = 'A020'
	//--	
	call SaveInteger(udg_AbilityDataHashTable , abilityId , StringHash("NEXT_ABILITY") , 'A021')
	call SaveInteger(udg_AbilityDataHashTable , abilityId , StringHash("HOTKEY") , StringHash("Q"))
	call SaveInteger(udg_AbilityDataHashTable , abilityId , StringHash("MASTERY_ID") , StringHash("JUMP_SLASH_MASTERY"))
	call SaveStr(udg_AbilityDataHashTable , abilityId , StringHash("NAME") , "跳砍")
	call SaveInteger(udg_AbilityDataHashTable , abilityId , StringHash("MAX_LEVEL") , 3)
	call SaveHashtableHandle(udg_AbilityDataHashTable , abilityId , StringHash("LEVEL_MASTERY_TABLE") , masteryTable)
	call SaveReal(masteryTable , 1 , 0 , 7.0) //30
	call SaveReal(masteryTable , 2 , 0 , 16.0) //70
	call SaveReal(masteryTable , 3 , 0 , 30.0) //120

	set gg_trg_JumpSlash = CreateTrigger()
	call TriggerRegisterPlayerForceUnitEvent(gg_trg_JumpSlash , EVENT_PLAYER_UNIT_SPELL_EFFECT)
	call TriggerAddAction(gg_trg_JumpSlash , function JumpSlashTry)	
endfunction